package com.zzjson.strategy.config;


import com.zzjson.util.DESCodec;

class SourcesPropertyDecoder {

    public String decode(String originalValue) {
        return originalValue;
    }

    static class DESSourcesPropertyDecoder extends SourcesPropertyDecoder {
        private static final String candidate_prefix = "key:";
        private static final String key = "11";

        @Override
        public String decode(String originalValue) {
            if (originalValue.startsWith(candidate_prefix)) {
                int prefixLen = candidate_prefix.length();
                String value = originalValue.substring(prefixLen);
                try {
                    return DESCodec.decode(value, key);
                } catch (Exception ex) {
                    throw new DecodeException("Cannot convert property : " + originalValue, ex);
                }
            }
            return originalValue;
        }
    }

    static class DecodeException extends RuntimeException {
        private static final long serialVersionUID = 1L;

        public DecodeException(String msg) {
            super(msg);
        }

        public DecodeException(String msg, Throwable cause) {
            super(msg, cause);
        }
    }
}
